﻿using System;
using Loong.Domain.Uow;

namespace Loong.Dapper.Uow
{
    public static class UnitOfWorkExtensions
    {
        public static ActiveTransactionInfo GetActiveTransaction(this IActiveUnitOfWork unitOfWork)
        {
            if (unitOfWork == null)
            {
                throw new ArgumentNullException("unitOfWork");
            }

            if (!(unitOfWork is DapperUnitOfWork))
            {
                throw new ArgumentException($"unitOfWork is not type of {typeof(DapperUnitOfWork).FullName} unitOfWork");
            }

            return (unitOfWork as DapperUnitOfWork).GetOrCreateTransaction();
        }
    }
}
